<template>
  <div v-if="loginStatus">
    <Login></Login>
  </div>
  <div v-else>
    <el-container>
      <!--头部-->
      <el-header>
        <Header/>
      </el-header>
      <!--左侧边栏-->
      <el-container>
        <el-aside width="200px" height="700px">
          <Menu/>
        </el-aside>
        <!--主体-->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>

    </el-container>
  </div>
</template>

<script>
  import Header from '@/components/Common/Header'
  import Menu from '@/components/Common/Menu'
  import Login from '@/components/Login/Login'

  export default {
    name: 'Base',
    components: {
      Header,
      Menu,
      Login
    },
    data() {
      return {
        isShow: true
      }
    },

    created() {
      // this.skipHome();
      this.getChoices();
    },
    methods: {
      skipHome() {
        if (!this.loginStatus) {
          this.$router.push({path: '/'});
        }
      },
      //获取项目的所有Choices
      getChoices() {
        this.$http.getApiFunc(this.$http.getApiStatus)(this.$http.choicesURL)
          .then(res => {
            this.CHOICES = res.data;
            let obj = JSON.stringify(res.data);
            localStorage.setItem('choicesInfo', obj);
            this.$store.dispatch('getChoicesInfo', res.data);
          })
          .catch(err => {
            console.log(err);
          })
      },
    },

    computed: {
      loginStatus() {
        // console.log(this.$store.state.userInfo.access_token);
        if (this.$store.state.userInfo) {
          if (this.$store.state.userInfo.access_token) {
            this.isShow = false;
          } else {
            this.isShow = true;
          }
        } else {
          this.isShow = true;
        }
        return this.isShow
      }
    }
  };
</script>

<style scoped>
  .el-header, .el-footer {
    background-color: #545c64;
    color: #333;
    padding: 0;
    text-align: center;
    line-height: 60px;
  }

  .el-aside {
    background-color: #D3DCE6;
    color: #333;
    /*text-align: center;*/
    line-height: 200px;
  }

  .el-main {
    background-color: #E9EEF3;
    color: #333;
    /*text-align: center;*/
    /*line-height: 160px;*/
  }

  body > .el-container {
    margin-bottom: 40px;
  }

  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }

  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }
</style>
